#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;

class Solution {
public:
    vector<int> addToArrayForm(vector<int>& A, int K) {
        int t = 0;
        int i = A.size()-1;
        while(K!=0&&i>=0){
            //定义提取出的数
            int f = K%10;
            if(f+t+A[i]<10){
                A[i] = f+t+A[i];
                t = 0;
            }
            else{
                int temp = (f+t+A[i]);
                A[i] = temp%10;
                t = temp/10;
            }
            K = K/10;
            i = i-1;    
        }
        if(t!=0&&K==0){
            while(t!=0){
                if(i>=0){
                    if(A[i]+t<10){
                        A[i] = A[i]+t;
                        t =0 ;
                    }
                    else{
                        int temp = (A[i]+t);
                        A[i] = temp%10;
                        t = temp/10;
                        i = i-1;
                    }
                }
                else{
                    A.insert(A.begin(),t);
                    t=0;
                }
            }
        }
        else if(K!=0){
            K = K+t;
            while(K!=0){
                A.insert(A.begin(),K%10);
                K = K/10;
            }
        }
   
        return A;
    }
};

int main(){
    Solution S;
    vector<int> v = {9,9,9,9,9,9};
    vector<int> result = S.addToArrayForm(v,1);
    return 0;
}